// src/pages/M{edical/Referral/index.jsx
import React ,{useEffect,useState} from 'react';
import { List, Button, NavBar } from 'antd-mobile';
import { useNavigate } from 'react-router-dom';
import StatusTag from '../StatusTag';
import axios from 'axios';
const ReferralList = () => {
  const navigate = useNavigate();
  const [zhuanlist, setzhuanlist] = useState([])
  const referrals=[
      {
        _id: '1',
        huanName: '李四',
        age: 35,
        fromDepartment: '普内科',
        toDepartment: '神经内科',
        status: 'pending',
        date: '2024-01-21',
        desc: '疑似神经系统疾病'
      },
      
        {
          "_id": '2',
          "huanName": "王芳",
          "age": 42,
          "fromDepartment": "呼吸内科",
          "toDepartment": "重症医学科",
          "status": "approved",
          "date": "2024-02-18",
          "desc": "重症肺炎伴呼吸衰竭，需ICU监护治疗"
        },
        {
          "_id": '3',
          "huanName": "张伟",
          "age": 58,
          "fromDepartment": "消化内科",
          "toDepartment": "普外科",
          "status": "rejected",
          "date": "2024-03-05",
          "desc": "疑似急性阑尾炎，但检查结果不符合手术指征"
        },
        {
          "_id": '4',
          "huanName": "陈晨",
          "age": 27,
          "fromDepartment": "急诊科",
          "toDepartment": "心内科",
          "status": "pending",
          "date": "2024-04-12",
          "desc": "胸痛待查，心电图显示ST段抬高"
        }
      
    ]

    const gethuilist = () => {
      axios.get('http://localhost:3000/zhuan/zhuanlist').then((res) => {
        const huis = [...referrals, ...res.data.list].flat();
        setzhuanlist(huis);
      });
    };
  
    useEffect(() => {
      gethuilist();
    }, []);
  return (
    <div className="referral-page">
      {/* <NavBar back={null}>转诊管理</NavBar> */}

      <Button
        color="primary"
        block
        onClick={() => navigate('/layout/referral/zhuan')}
        style={{width:334,margin:'0 auto',marginTop:20}}
      >
        申请转诊
      </Button>

      <List header="转诊列表">
        {zhuanlist.map(item => (
          <List.Item
            key={item._id}
            onClick={() => navigate(`${item._id}`)}
            title={item.huanName}
            description={
              <>
                <div>{`${item.age}岁`}</div>
                <div>{`${item.fromDepartment} → ${item.toDepartment}`}</div>
                <div>{item.desc}</div>
              </>
            }
            extra={<StatusTag status={item.status} />}
          />
        ))}
      </List>

    </div>
  );
};

export default ReferralList;